﻿namespace Algorithms_DataStruct_Lib.Search;

public class Searching
{
    public static int BinarySearch(int[] arr, int value)
    {
        int low = 0;
        int high = arr.Length;
        while (low < high)
        {
            int mid = (high + low) / 2;
            if (arr[mid] == value)
            {
                return mid;
            }

            if (arr[mid] < value)
            {
                low = mid + 1;
            }
            else
            {
                high = mid;
            }
        }

        return -1;
    }
}